package com.medical.manage.controller;

import com.medical.common.core.domain.Result;
import com.medical.common.core.web.controller.BaseController;
import com.medical.common.log.annotation.Log;
import com.medical.common.log.enums.BusinessType;
import com.medical.common.security.annotation.RequiresPermissions;
import com.medical.manage.domain.Department;
import com.medical.manage.domain.Medicine;
import com.medical.manage.domain.Pharmacology;
import com.medical.manage.mapper.PharmacologyMapper;
import com.medical.manage.service.PharmacologyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @Author：waikaipeng
 * @Package：com.medical.manage.controller
 * @Project：medical
 * @name：PharmacologyController
 * @Date：2025年3月7日 00:02
 */
@RestController
@RequestMapping("/pharmacology")
public class PharmacologyController extends BaseController {
    @Autowired
    private PharmacologyService pharmacologyService;

    //药理分类查询
    @RequiresPermissions("manage:pharmacology:list")
    @GetMapping("/list")
    public Result list(Pharmacology pharmacology){
        startPage();
        List<Pharmacology> list = pharmacologyService.list();
        return getDataTable(list);
    }

    //药理添加
    @RequiresPermissions("manage:pharmacology:add")
    @Log(title = "药理详情", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Pharmacology pharmacology){
        pharmacologyService.save(pharmacology);
        return success();
    }


    //药理修改
    @RequiresPermissions("manage:pharmacology:edit")
    @Log(title = "药理详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Pharmacology pharmacology){
        pharmacologyService.updateById(pharmacology);
        return success();
    }



    //药理删除
    @RequiresPermissions("manage:pharmacology:remove")
    @Log(title = "药理详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pharmacologyIds}")
    public Result delete(@PathVariable Long[] pharmacologyIds){
        List<Long> list = Arrays.asList(pharmacologyIds);
        pharmacologyService.removeBatchByIds(list);
        return success();
    }
}
